import Axios from '@/util/ajax'

const state = {
    isInitialized: false,
    //保存报价所有页面都会用到的一些值 ：如下拉框的列表值等,
    initPageData: {
        customers: [], // 客户列表
        sells:[], // 销售人员
        statusList:[],
    },
    paymentList: [],
    payment:{},
    showPaymentList: false,
    isView: false,
    showPaymentDialog: true,
    orderId: -1,
    selectedPayments: []
};

// 通过 mutation 去更改 state 里面的值
const mutations = {
    Show_Payment_List: (state, orderId) => {
        state.showPaymentList = true;
        state.showPaymentDialog = false;
        state.orderId = orderId;
        state.isView = false;
    },

    Set_Payment_List: (state, data) => {
        state.paymentList = data
    },

    Show_Add_Payment: (state) => {
        state.payment = {
            id: -1,
            paid: 0.00,
            paidDt: new Date(),
            orderId: state.orderId,
        };
        state.showPaymentDialog = true;
        state.isView = false;
    },

    Set_Show_Payment_List: (state, data) => {
        state.showPaymentList = data
    },

    Show_Edit_Payment: (state, payment) => {
        Object.assign(state.payment, payment);
        state.showPaymentDialog = true;
        state.isView = false;
    },

    Hide_Payment_Dialog: (state) => {
        state.showPaymentDialog = false
    },

    Set_Selected_Payment: (state, data) => {
        state.selectedPayments = data
    },
};

// 通过 action 去 commit mutation
const actions = {

    async loadInitPageData({state}) {
        //if(!state.isInitialized){
            state.showPaymentList = false;
            let res = await Axios.get('/finance/payment/loadInitPageData', {});
            console.log("初始化查询页面：", res.result);
            state.initPageData = res.result;
            state.isInitialized = true;
        //}
    },

    showViewPayment({state}, orderId) {
        state.showPaymentList = true;
        state.orderId = orderId;
        state.isView = true;
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
